//
//  SinaTabBar.m
//  oc微博
//
//  Created by 安陆与 on 16/1/13.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaTabBar.h"
#import "UIView+Ex.h"

@interface  SinaTabBar()

@property (nonatomic, weak) UIButton * composeBtn;

@end


@implementation SinaTabBar


-(instancetype)init{

    if (self = [super init]) {
        
        [self setupCompostBtn];

    }

    return self;
}

-(void)layoutSubviews{

    [super layoutSubviews];
    
    self.composeBtn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);

    self.backgroundColor = [UIColor greenColor];
    
    
    
     //添加其他按钮
    CGFloat index = 0;
    
    CGFloat width = self.bounds.size.width / 5.0;
    
    
    for (UIButton *btn in self.subviews) {

      
        if ([btn isKindOfClass:(NSClassFromString(@"UITabBarButton"))]) {
            
            btn.frame = CGRectMake(index * width, 0, width, self.bounds.size.height);
            
            index ++;
            
            if (index == 2) {
                index ++;

        }
        
        
//        if (index == 0) {
//            btn.frame = CGRectMake(0, 0, self.width, self.height);
//        }
//            
//            btn.frame = CGRectMake((index - 1) * width, 0, width, self.bounds.size.height);
//            
//            index ++;
//            
//            if (index == 3) {
//                index ++;
//            }
    
        }
    
    }

}



//设置中间按钮
-(void)setupCompostBtn{
    //添加中间的按钮
    UIButton *compostBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self addSubview:compostBtn];

    
    self.composeBtn = compostBtn;
    //设置位置
//    compostBtn.center = self.center;
    
    [compostBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [compostBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [compostBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add" ] forState:UIControlStateNormal];
    [compostBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    [compostBtn sizeToFit];
    

}


@end










